/*
 * Part of the ACID Project
 * Developed in 2011 by Morgan Taschuk
 */
package acid.plugin.gui;

import java.net.URLEncoder;

/**
 *
 * @author morgan
 */
public class ChartUrl
{

    private static String baseUrl = "http://chart.apis.google.com/chart?";
    private static String baseSize = "&chs=";
    private static String baseType = "&cht=";
    private static String baseColours = "&chco=";
    private static String baseValues = "&chd=t:";
    private static String baseLabels = "&chl=";
    private static String baseBg = "&chf=";

    private ChartUrl()
    {
    }

    public static String basicChart(Double[] vals)
    {
        String[] labels = new String[]
        {
            "Up", "Down", "NoChange"
        };
        return basicChart(vals, labels);
    }

    public static String titledChart(Double[] vals, String title)
    {
        try
        {
            title = URLEncoder.encode(title, "UTF-8");
        }
        catch (Exception ignore)
        {
        }
        title = title.replace("-", "|");
        return basicChart(vals) + "&chtt=" + title+"&chts=000000,10";
    }

    public static String basicChart(Double[] vals, String[] labels)
    {
        String size = baseSize + "100x100";
        String type = baseType + "p";
        String colours = baseColours + "FFFF88,3072F3,FF44FF";
        String bg = baseBg + "bg,s,FFFFFF00";

        return basicChart(vals, labels, size, type, colours, bg);
    }

    public static String basicChart(Double[] vals, String[] labels, String size,
            String type, String colours, String bg)
    {
        String values = baseValues;
        for (Double d : vals)
        {
            values += d + ",";
        }

        String labelstr = baseLabels;
        for (String l : labels)
        {
            labelstr += l + "|";
        }
        return baseUrl + size + type + colours
                + values.substring(0, values.length() - 1)
                //+ labelstr.substring(0, labelstr.length()-1)
                + bg;


    }
}
